package com.jeff.android.lab.homecomponent;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.jeff.android.lab.commonlib.router.provider.IDataProvider;
import com.jeff.android.lab.commonlib.router.Constant;
import com.jeff.utils.ToastUtil;

@Route(path = Constant.ACTIVITY_URL_HOME)
public class HomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_activity_main);
        setTitle("Home 模块，首页");

        ARouter.getInstance().inject(this);

        findViewById(R.id.btn_get_data)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        getData();
                    }
                });

    }

    private void getData() {
        // by name
        IDataProvider provider = (IDataProvider) ARouter
                .getInstance()
                .build("/provider/data")
                .navigation();

        // by type (有多个实现的时候，不适合使用该种方式)
//        IDataProvider provider = ARouter.getInstance()
//                .navigation(IDataProvider.class);

        ToastUtil.show(this, "" + provider.getData());
    }

}
